<template>
    <div>
        <div class="info-form" >
            <el-form :model="addForm" :inline="true" v-if="addForm.switch">
                <el-form-item label="寝室:">
                    <el-input v-model="addForm.dname"></el-input>
                </el-form-item>
                <el-form-item label="可住人数:">
                    <el-input v-model="addForm.size"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm()">提交</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div>
            <el-table
                    :data="tableData"
                    stripe
                    style="width: 100%">
                <el-table-column
                        prop="dname"
                        label="寝室">
                </el-table-column>
                <el-table-column
                        prop="size"
                        label="可住人数">
                </el-table-column>
                <el-table-column
                        prop="name"
                        label="已住人数">
                </el-table-column>
                <el-table-column label="操作">
                    <template scope="scope">
                        <el-button @click="handleClick(scope.$index)" type="text" size="small">查看</el-button>
                        <el-button @click.native.prevent="deleteRow(scope.$index, items)" type="text" size="small"> 删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
    import moment from 'moment';
    import * as type from '../../../store/types';
    export default {
        data() {
            return {
                addForm: {
                    switch:false
                },
                tableData: []
            }
        },
        activated(){
            let user = JSON.parse(localStorage.getItem("currentUser"));
            if(user.account == "system"){
                this.addForm.switch = true;
            }
            this.get();
        },
        methods: {
            submitForm(){
                let self = this;
                let dormitories = this.addForm;
                this.$axioxs.post("/dormitories/save", dormitories)
                    .then(function (res) {
                        self.get();
                    })
            },
            get(){
                let self = this;
                this.$axioxs.get("/dormitories/get")
                    .then(function (res) {
                        self.tableData = res.data.records;
                    })
            },
            handleClick(index) {
//                this.$store.commit(type.CHANGE_INDEX, '/setdormitories');
                this.$router.push({
                    path: '/setdormitories',
                    query: {item: this.tableData[index]}
                });
            },
            deleteRow(index, rows) {

            }
        }
    }
</script>